package com.goldcn.user.controller;

import com.goldcn.user.model.Config;
import com.goldcn.user.service.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 1111 on 2017/3/17.
 */
@Api(value = "封面配置")
@RestController
@RequestMapping(value = "/config")
public class ConfigController {
    @Autowired
    ConfigService configService;

    @ApiOperation(value = "增加封面配置")
    @RequestMapping(method = RequestMethod.POST)
    public Object addConfig(@RequestBody Config config){
        return configService.addUpdateConfig(config,1);
    }

    @ApiOperation(value = "修改封面配置")
    @RequestMapping(method = RequestMethod.PUT)
    public Object updateConfig(@RequestBody Config config){
        return configService.addUpdateConfig(config,2);
    }

    @ApiOperation(value = "删除封面配置")
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public Object deleteConfig(@PathVariable Long id){
        return configService.deleteConfig(id);
    }

    @ApiOperation(value = "按id查询封面配置")
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public Object getConfigByID(@PathVariable Long id){
        return configService.getConfigByID(id);
    }

    @ApiOperation(value = "查询所有封面配置")
    @RequestMapping(method = RequestMethod.GET)
    public Object getConfigAll(){
        return configService.getConfigAll();
    }

    @ApiOperation(value = "查询借货开关")
    @RequestMapping(value = "orderBorrow/{companyID}",method = RequestMethod.GET)
    public Object orderBorrow(@PathVariable Long companyID){
        Config config= (Config) configService.getConfigByID(companyID);
        return config==null?"setting is null":config.getOrderBorrow();
    }

    @ApiOperation(value = "查询借货审核级别设置")
    @RequestMapping(value = "orderBorrowAuditLevel/{companyID}",method = RequestMethod.GET)
    public Object getOrderBorrowAuditLevel(@PathVariable Long companyID){
        Config config= (Config) configService.getConfigByID(companyID);
        return config==null?"setting is null":config.getOrderBorrowAuditLevel();
    }

    @ApiOperation(value = "查询会员价开关")
    @RequestMapping(value = "vipPrice/{companyID}",method = RequestMethod.GET)
    public Object vipPrice(@PathVariable Long companyID){
        Config config= (Config) configService.getConfigByID(companyID);
        return config==null?"setting is null":config.getVipPrice();
    }

    @ApiOperation(value = "查询奖金开关")
    @RequestMapping(value = "isClazzSupply/{companyID}",method = RequestMethod.GET)
    public Object isClazzSupply(@PathVariable Long companyID){
        return configService.isClazzSupply(companyID);
    }

    @ApiOperation(value = "查询横排展示的分类ID(赣州银行需求、钻石)")
    @RequestMapping(value = "queryDiamondClazzID",method = RequestMethod.GET)
    public Object querySubClazzID(){
        return configService.queryDiamondClazzID();
    }
}
